﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using SR.API;

namespace SR.UI.WebPart.NivoSlider.NivoSliderWebPart
{
    public partial class NivoSliderWebPartUserControl : UserControl
    {
        public NivoSliderWebPart parentControl { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                ClientScriptManager scriptmgr = this.Page.ClientScript;
                if (parentControl.SkipJQuery == false)
                    scriptmgr.RegisterClientScriptInclude("jquery", "/_layouts/SR.UI.WebPart.NivoSlider/scripts/jquery-1.7.1.min.js");
                scriptmgr.RegisterClientScriptInclude("Nivo", "/_layouts/SR.UI.WebPart.NivoSlider/jquery.nivo.slider.js");
                List<SliderImage> images = SliderImageUtility.GetSliderImages(parentControl.SiteUrl, parentControl.ListName, parentControl.Count, parentControl.LinkUrl, Convert.ToString(parentControl.SlideTransition));
                repImages.ItemTemplate = new SR.API.NivoTemplate();
                repImages.DataSource = images;
                repImages.DataBind();
            }
            catch (Exception ex)
            {
                throw ex.AppendException("Cannot get the images");
            }
        }

        public string GetSliderTheme()
        {
            switch (this.parentControl.SliderTheme)
            {
                case SliderThemes.def: return "theme-default";
                case SliderThemes.orman: return "theme-orman";
                case SliderThemes.pascal: return "theme-pascal";
                default: return "default";
            }
        }

        public string GetDataTransition()
        {
            switch (this.parentControl.SlideTransition)
            {
                case SliderTransitionEffects.sliceDown:
                    return "sliceDown";
                case SliderTransitionEffects.sliceDownLeft:
                    return "sliceDownLeft";
                case SliderTransitionEffects.sliceUp:
                    return "sliceUp";
                case SliderTransitionEffects.sliceUpLeft:
                    return "sliceUpLeft";
                case SliderTransitionEffects.sliceUpDown:
                    return "sliceUpDown";
                case SliderTransitionEffects.sliceUpDownLeft:
                    return "sliceUpDownLeft";
                case SliderTransitionEffects.fold:
                    return "fold";
                case SliderTransitionEffects.fade:
                    return "fade";
                case SliderTransitionEffects.random:
                    return "random";
                case SliderTransitionEffects.slideInLeft:
                    return "slideInLeft";
                case SliderTransitionEffects.slideInRight:
                    return "boxRainGrow";
                case SliderTransitionEffects.boxRandom:
                    return "boxRandom";
                case SliderTransitionEffects.boxRain:
                    return "boxRain";
                case SliderTransitionEffects.boxRainReverse:
                    return "boxRainReverse";
                case SliderTransitionEffects.boxRainGrow:
                    return "boxRainGrow";
                case SliderTransitionEffects.boxRainGrowReverse:
                    return "boxRainGrowReverse";
                default:
                    return "random";
            }

        }

    }
}
